package com.wuneng.ircontrol.common.util;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.TextView;

import com.wuneng.commonlibrary.base.BaseActivity;

import java.util.List;

import butterknife.ButterKnife;


public abstract class MyBaseAct extends BaseActivity {
    protected Context THIS = this;

    @Override
    protected int getContentViewLayoutID() {
        return getMyContentViewLayoutID();
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        initMyView();
    }

    @Override
    protected void initData() {
        initMyData();
    }

    protected abstract void bindListener();

    @Override
    protected boolean isInitEventBus() {
        return false;
    }

    @Override
    protected void handleNfcCode(String code, int type) {
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected boolean isEnableDoubleClickExit() {
        return false;
    }


    protected abstract void initMyView();

    protected abstract void initMyData();

    protected abstract int getMyContentViewLayoutID();



    /**
     * 单项选择框
     *
     * @param tv
     * @param title
     * @param datas
     */
    public void showSingSelect(final TextView tv, final String title, final List<String> datas) {
        final String[] items = new String[datas.size()];
        for (int i = 0; i < datas.size(); i++) {
            items[i] = datas.get(i);
        }


        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                tv.setText(items[which]);
                dialog.dismiss();
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }

}
